﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WS.EKA.Business.Dal;
using WS.EKA.Business.Model;
using WS.EKA.UI.Business;

namespace WS.EKA.Web.UI.Pages
{
    public partial class ITNotienceManagement : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
            if (!Page.IsPostBack)
            {
                LoadLastPublishAnnounce();
            }
        }

        protected void Save_Click(object sender, EventArgs e)
        {
            string onduty = this.Onduty.Text;
            string announce = this.AnnounceMent.Text;
            string importantTask = this.ImportantTask.Text;
            //if (string.IsNullOrEmpty(onduty) && string.IsNullOrEmpty(announce)
            //    && string.IsNullOrEmpty(importantTask))
            //{
            //    WebMessageBox(this, "请输入相关发布内容");
            //    return;
            //}
            //if (!string.IsNullOrEmpty(onduty))
            //{
            //}

            //if (!string.IsNullOrEmpty(announce))
            //{
            //}

            //if (!string.IsNullOrEmpty(importantTask))
            //{
            //}

            ITAnnouncementAccess.AddOnDuty(new OnDuty()
            {
                Content = string.IsNullOrEmpty(onduty) ? " " : onduty,
                CreateTime = DateTime.Now
            });
            ClientDataSourceBridge.Push(WebSocketClientType.ITNotice_OnDuty);

            ITAnnouncementAccess.AddAnnounceMent(new AnnounceMent()
            {
                Content = string.IsNullOrEmpty(announce) ? " " : announce,
                CreateTime = DateTime.Now
            });
            ClientDataSourceBridge.Push(WebSocketClientType.ITNotice_AnnounceMent);

            ITAnnouncementAccess.AddLatestImportantTask(new LatestImportantTask()
            {
                Content = string.IsNullOrEmpty(importantTask) ? " " : importantTask,
                CreateTime = DateTime.Now
            });
            ClientDataSourceBridge.Push(WebSocketClientType.ITNotice_LatestImportantTask);
            WebMessageBox(this, "发布成功");
        }

        private void LoadLastPublishAnnounce()
        {
            ITAnnounceMent obj = ITAnnouncementAccess.GetLatestOnDuty().FirstOrDefault();
            if (obj != null)
            {
                this.Onduty.Text = obj.Content;
            }
            obj = ITAnnouncementAccess.GetAnnounceMent(1).FirstOrDefault();
            if (obj != null)
            {
                this.AnnounceMent.Text = obj.Content;
            }
            obj = ITAnnouncementAccess.GetLatestImportantTask(1).FirstOrDefault();
            if (obj != null)
            {
                this.ImportantTask.Text = obj.Content;
            }
        }

    }
}